<?php
	require_once "Administrador.php";
	class Sessao extends Administrador
	{			
		function __construct()
		{
			@session_start();
			//$this->Ip = '';
		}
		
		/*
		private $Ip;
		
		public function GetIp(){return $this->Ip;}
		
		public function SetIp($_value)
		{
			$this->Ip = $_value;
		}
		
		public function GerarLog($_id)
		{
			$_query = mysql_query("INSERT INTO LOG VALUES(null,now(),$_id,'$this->Ip')");				
		}
		*/
		
		public function Autenticar()
		{			
			$_query = mysql_query("SELECT id_administrador,nome,email,data_cadastro FROM administrador WHERE email = '$this->Email' AND Senha = '$this->Senha'");
			$_verifica = mysql_num_rows($_query);
			if($_verifica == 1)
			{
				$_linha  = mysql_fetch_array($_query);
				$Administrador = new Administrador();
				$Administrador->Carregar($_linha['id_administrador']);
				$_SESSION["usudados"] = $Administrador;
				$_SESSION["mensagens"]["alerta"];
				//$this->GerarLog($_linha['id_administrador']);
				header("location:administrador.php");
			}
			else			
				echo "<script>alert('login ou senha inválido')</script>";					
		}
		
		
		
		function Logado()
		{
			if(!isset($_SESSION["usudados"]))
			{
				header("location:index.php");
			}			
		}
		
		
		function Logout()
		{
			session_destroy(); 
			header("location:index.php");
		}
		
		
		function TelasRestritas($pagina) 
		{			  
			/*if(!(isset($_SESSION["usuariodados"])) && ($pagina == "usuario.php"))
				header("location:index.php");
			elseif(!(isset($_SESSION["usuariodados"])) && ($pagina == "comprar.php"))
				header("location:confirmacao.php"); 
			if((isset($_SESSION["usuariodados"])) && ($pagina == "confirmacao.php"))
				header("location:comprar.php");*/
		}
	}			
?>